package com.tywj.lib.core.common.util

import java.util.regex.Pattern

/**
 * <pre>
 *     author : June Yang
 *     time   : 2020/5/7
 *     desc   : 正则表达式工具类
 *     version: 1.0.0
 * </pre>
 */
object RegexUtil {
    // 英文正则表达式
    private const val REGEX_ENGLISH = "^[a-zA-Z]+$"
    // 中文正则表达式
    private const val REGEX_CHINESE = "^[\\u4e00-\\u9fa5]+$"
    //中文或英文正则表达式
    private const val REGEX_CHINESE_OR_ENGLISH = "^[A-Za-z\\u4e00-\\u9fa5]+\$"
    // 手机号正则表达式
    private const val REGEX_PHONE = "^1(3|4|5|7|8|9)\\d{9}$"
    // 18位身份证号正则表达式
    private const val REGEX_ID_CARD18 = "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9Xx])$"
    // 数字正则表达式
    private const val REGEX_DIGIT = "^[0-9]+.?[0-9]*$"
    //过虑文本表达式
    const val REGEX_STRING = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？]"

    private fun matches(regex: String, content: String): Boolean = Pattern.matches(regex, content)

    fun isEnglish(content: String): Boolean =
        matches(
            REGEX_ENGLISH,
            content
        )

    fun isChinese(content: String): Boolean =
        matches(
            REGEX_CHINESE,
            content
        )

    fun isChineseOrEnglish(content: String): Boolean =
        matches(
            REGEX_CHINESE_OR_ENGLISH,
            content
        )

    fun isPhone(content: String): Boolean =
        matches(
            REGEX_PHONE,
            content
        )

    fun isIDCard18(content: String): Boolean =
        matches(
            REGEX_ID_CARD18,
            content
        )

    fun isDigit(content: String): Boolean =
        matches(
            REGEX_DIGIT,
            content
        )
}